//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.batteryhelper;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Parcelable;

import java.io.File;
import java.lang.annotation.Documented;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

@Deprecated
public class SpUtil  {
    private SharedPreferences shref;
    private String shrefName;
    private String shrefDir;
    private static HashMap<String, SpUtil> SP_MAP = new HashMap();
    private static Context context;

    public static void init(Context context){
        SpUtil.context=context;
    }

    public static synchronized SpUtil get(String name){

        if (!SP_MAP.containsKey(name)){
            SP_MAP.put(name, new SpUtil(name));
        }

        return SP_MAP.get(name);
    }

    private SpUtil() {
        this("default_sharedpreferences");
    }

    private SpUtil(String shrefName) {
        this(shrefName, 0);
    }

    private SpUtil(String shrefName, int mode) {
        if (context==null){
            throw new RuntimeException("SpUtil.init() 没有初始化");
        }
        this.shref = context.getSharedPreferences(shrefName, mode);
        this.shrefName = shrefName;
    }

    private String getCacheDir(Context context) {
        return File.separator + "data" + File.separator + "data" + File.separator + context.getPackageName() + File.separator + "shared_prefs";
    }

    public boolean isCacheFileExists() {
        File file = new File(this.shrefDir, this.shrefName + ".xml");
        return file != null ? file.exists() : false;
    }

    public final long lastModified() {
        File file = new File(this.shrefDir, this.shrefName + ".xml");
        return file != null && file.exists() ? file.lastModified() : 0L;
    }

    public final void saveData(String key, String value) {
        this.saveData(key, value, false);
    }

    public final void saveData(String key, String value, boolean commit) {
        Editor editor = this.shref.edit();
        editor.putString(key, value);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public final void saveData(String key, int value) {
        this.saveData(key, value, false);
    }

    public final void saveData(String key, int value, boolean commit) {
        Editor editor = this.shref.edit();
        editor.putInt(key, value);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public final void saveData(String key, boolean value) {
        this.saveData(key, value, false);
    }

    public final void saveData(String key, boolean value, boolean commit) {
        Editor editor = this.shref.edit();
        editor.putBoolean(key, value);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public final void saveData(String key, long value) {
        this.saveData(key, value, false);
    }

    public final void saveData(String key, long value, boolean commit) {
        Editor editor = this.shref.edit();
        editor.putLong(key, value);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public final void saveData(String key, float value) {
        this.saveData(key, value, false);
    }

    public final void saveData(String key, float value, boolean commit) {
        Editor editor = this.shref.edit();
        editor.putFloat(key, value);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public final void saveData(String key, Set<String> value) {
        this.saveData(key, value, false);
    }

    public final void saveData(String key, Set<String> value, boolean commit) {
        Editor editor = this.shref.edit();
        editor.putStringSet(key, value);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public void saveData(String key, Parcelable parcelable) {
        throw new UnsupportedOperationException("sp not support this method");
    }

    public final String readString(String key) {
        return this.readString(key, (String)null);
    }

    public final String readString(String key, String defaultValue) {
        return this.shref.getString(key, defaultValue);
    }

    public final int readInt(String key) {
        return this.readInt(key, 0);
    }

    public final int readInt(String key, int defalValue) {
        return this.shref.getInt(key, defalValue);
    }

    public final boolean readBoolean(String key) {
        return this.readBoolean(key, false);
    }

    public final boolean readBoolean(String key, boolean defaultValue) {
        return this.shref.getBoolean(key, defaultValue);
    }

    public final long readLong(String key) {
        return this.readLong(key, 0L);
    }

    public final long readLong(String key, long defaultValue) {
        return this.shref.getLong(key, defaultValue);
    }

    public final float readFloat(String key) {
        return this.readFloat(key, 0.0F);
    }

    public final float readFloat(String key, float defaultValue) {
        return this.shref.getFloat(key, defaultValue);
    }

    public final HashSet<String> readSetString(String key) {
        return new HashSet(this.shref.getStringSet(key, new HashSet()));
    }

    public final HashSet<String> readSetString(String key, Set<String> defaultValue) {
        return new HashSet(this.shref.getStringSet(key, defaultValue));
    }

    public <T extends Parcelable> T readParcelable(String key, Class<T> tClass) {
        throw new UnsupportedOperationException("sp not support this method");
    }

    public final boolean contains(String key) {
        return this.shref.contains(key);
    }

    public final void remove(String key) {
        this.remove(key, false);
    }

    public final void remove(String key, boolean commit) {
        Editor editor = this.shref.edit();
        editor.remove(key);
        if (commit) {
            editor.commit();
        } else {
            editor.apply();
        }

    }

    public final void clear() {
        Editor editor = this.shref.edit();
        editor.clear();
        editor.apply();
    }

    public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener, boolean regist) {
        if (regist) {
            this.shref.registerOnSharedPreferenceChangeListener(listener);
        } else {
            this.shref.unregisterOnSharedPreferenceChangeListener(listener);
        }

    }
}
